
public class Lista {
	Node head;
	
	Lista()
	{
		head = null;
	}
	
	void addFirst(int n)
	{
		head = new Node(n, head);
	}
	
	Node removeFirst()
	{
		if (head == null) return head;
		Node res = head; 
		head = head.next;
		return res;
	}
	
	private void printRec(Node h)
	{
		if (h == null) 
		{
			System.out.println();
			return;
		}
		System.out.printf("%d ", h.val);
		printRec(h.next);
	}
	
	public void printRec()
	{
		printRec(head);
	}
	
	void print()
	{
		Node curr = head;
		System.out.println("Lista:");
		while(curr != null)
		{
			System.out.println(curr.val);
			curr = curr.next;
		}
		System.out.println("Kraj!");
	}
	
	void addLast(int n)
	{
		Node curr = head;
		Node newNode = new Node(n);
		
		if (curr == null) 
		{
			curr = newNode;
			return;
		}
		
		while(curr.next != null)
		{
			curr = curr.next;
		}
		curr.next = newNode;
	}
}
